import { createI18n } from 'vue-i18n'

import enGb from './en-gb.json'
import zhCn from './zh-cn.json'
import zhHk from './zh-hk.json'

const messages = {
	'en': enGb,
	'zh_cn': zhCn,
	'zh_hk': zhHk
}

const i18nConfig = {
  locale: uni.getStorageSync('user_language') || 'zh_cn',
  messages
}

// const i18n = createI18n(i18nConfig)
export const i18n = createI18n(i18nConfig)

export function setupI18n(app) {
	app.use(i18n)
}

// 抛出 $t
export const t = (key, ...args) => {
	return i18n.global.t(key, ...args)
}

// 抛出 $tm
export const tm = (key, ...args) => {
	return i18n.global.tm(key, ...args)
}